package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC2047 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int countValidWords(String sentence) {
            String[] ss = sentence.split(" ");
            int ans = 0;
            for (String s : ss) if (check(s)) ans++;
            return ans;
        }

        boolean check(String s) {
            int n = s.length();
            if (n == 0) return false;
            for (int i = 0, c1 = 0, c2 = 0; i < n; i++) {
                char c = s.charAt(i);
                if (Character.isDigit(c)) return false;
                if (c == ' ') return false;
                if (c == '-' && ++c1 >= 0) {
                    if (c1 > 1 || (i == 0 || i == n - 1)) return false;
                    if (!Character.isLetter(s.charAt(i - 1)) || !Character.isLetter(s.charAt(i + 1))) return false;
                }
                if ((c == '!' || c == '.' || c == ',') && ++c2 >= 0) {
                    if (c2 > 1 || (i != n - 1)) return false;
                }
            }
            return true;
        }
    }


    public void run() {
        Solution solution = new Solution();
        int[] arr = InputUtil.toIntegerArray("[1,2,3]");
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC2047 an = new LC2047();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
